package thread;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author Duanyu
 * @date 2021-11-19 17:13
 */
public class CollectionTest {

    private static volatile boolean flag = true;

    public static void main(String[] args) {
        List<Integer> list = new ArrayList();

        new Thread(()->{
            for (int i = 0; i < 10; i++) {
                list.add(i);
                System.out.println(i);
            }
        }).start();

        new Thread(()->{
            while (true){
                synchronized (list){
                    if (list.size() == 5){
                        System.exit(1);
                    }
                }
            }
        }).start();
    }

}

